package com.example.service.comment.impl;

import com.example.dao.comment.CourseCommentDao;
import com.example.pojo.Comment;
import com.example.service.comment.CourseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @program: demo
 * @description:
 * @author: yc
 * @create: 2023-02-02 15:17
 **/
@Service
public class CourseCommentServiceImpl implements CourseCommentService {
    @Autowired
    private CourseCommentDao dao;

    //课程评论
    @Override
    public List<Comment> getCommentList() {
        /*Comment comment = new Comment();
        Set<String> sensitiveWords=new HashSet<>();
        sensitiveWords.add("SB");
        sensitiveWords.add("共产党");
        sensitiveWords.add("傻逼");
        String text=comment.getContent();
        for(String sensitiveWord:sensitiveWords){
            if(text.contains(sensitiveWord)){
                System.out.println("输入的文字存在敏感词。——"+sensitiveWord);
                break;
            }
        }*/
        return dao.getCommentList();
    }

    //根据评论状态查询
    @Override
    public List<Comment> getCommentState(Integer state, String account, String nickname) {
        return dao.getCommentState(state,account,nickname);
    }

    //历史评论次数
    @Override
    public int getLiFrequency(Comment comment) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNow = sdf.format(new Date());
        comment.setCommentDate(dateNow);
        return dao.getLiFrequency(comment);
    }

    //历史评论人数
    @Override
    public int getLiPeople(Comment comment) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNow = sdf.format(new Date());
        comment.setCommentDate(dateNow);
        List<Comment> liPeople = dao.getLiPeople(comment);
        liPeople.size();
        return liPeople.size();
    }

    //今日评论次数
    @Override
    public int getJinFrequency(Comment comment) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNow = sdf.format(new Date());
        comment.setCommentDate(dateNow);
        return dao.getJinFrequency(comment);
    }

    //今日评论人数
    @Override
    public int getJinPeople(Comment comment) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNow = sdf.format(new Date());
        comment.setCommentDate(dateNow);
        List<Comment> jinPeople = dao.getJinPeople(comment);
        jinPeople.size();
        return jinPeople.size();
    }

    //通过
    @Override
    public int getTongGuo(Comment comment) {
        comment.setState(1);
        System.out.println("id:"+comment.getId());
        System.out.println("状态:"+comment.getState());
        return dao.getTongGuo(comment);
    }

    //拦截
    @Override
    public int getLanJie(Comment comment) {
        comment.setState(3);
        return dao.getLanJie(comment);
    }

    //删除
    @Override
    public void delComment(Integer id) {
        System.out.println(id);
        dao.delComment(id);
    }


}
    